package com.dengqi.mymodule.activity.empty;

import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.dengqi.mymodule.BaseActivity;
import com.dengqi.mymodule.BuildConfig;
import com.dengqi.mymodule.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


public class GloadingScrollActivity extends BaseActivity {

    protected Gloading.Holder mHolder;
    @BindView(R.id.textView3)
    TextView textView3;
    @BindView(R.id.layout)
    LinearLayout layout;
    @BindView(R.id.scroll)
    ScrollView scroll;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gloading_scroll);
        ButterKnife.bind(this);

        Gloading.debug(BuildConfig.DEBUG);
        Gloading.initDefault(new GlobalAdapter());

        if (mHolder == null) {
            //bind status view to activity root view by default
            mHolder = Gloading.getDefault().wrap(layout).withRetry(new Runnable() {
                @Override
                public void run() {
                    onLoadRetry();
                }
            });
        }
        layout.setVisibility(View.GONE);
        showLoadFailed();
    }


    private void loadData() {
        showLoading();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                layout.setVisibility(View.VISIBLE);
                showLoadSuccess();
            }
        }, 1500);
    }

    protected void onLoadRetry() {
        // override this method in subclass to do retry task
        loadData();
    }

    public void showLoading() {
        mHolder.showLoading();
    }

    public void showLoadSuccess() {
        mHolder.showLoadSuccess();
    }

    public void showLoadFailed() {
        mHolder.showLoadFailed();
    }

    public void showEmpty() {
        mHolder.showEmpty();
    }

    @OnClick({R.id.textView3, R.id.layout})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.textView3:
                break;
            case R.id.layout:
                break;
        }
    }
}
